using System.Windows.Controls;
using ShadeTree.Binding.Configuration;
using ShadeTree.Binding.Elements;

namespace ShadeTree.Binding.WPF
{
    public static class ExpressionExtensions
    {
        public static TextEditingElementExpression To(this PropertyBindingExpression expression, TextBox box)
        {
            IBindingData data = expression;

            var element = new TextboxElement(data.Accessor, box);
            data.Binder.AddElement(element);

            return new TextEditingElementExpression(element);
        }

        public static TextEditingElementExpression To(this PropertyBindingExpression expression, Label label)
        {
            IBindingData data = expression;

            var element = new LabelElement(data.Accessor, label);
            data.Binder.AddElement(element);

            return new TextEditingElementExpression(element);
        }

        public static CheckboxElementExpression To(this PropertyBindingExpression expression, CheckBox box)
        {
            IBindingData data = expression;

            var element = new CheckboxElement(data.Accessor, box);
            data.Binder.AddElement(element);

            return new CheckboxElementExpression(element);
        }

        public static ListElementExpression To(this PropertyBindingExpression expression, ComboBox box)
        {
            IBindingData data = expression;

            var element = new PicklistElement(data.Accessor, box);
            data.Binder.AddElement(element);

            return new ListElementExpression(element);            
        }

        public static ButtonElement BindButton<T>(this ScreenBinder<T> binder, Button button)
        {
            var element = new ButtonElement(button);
            binder.AddElement(element);

            return element;
        }

        public class CheckboxElementExpression : ScreenElementExpression<CheckboxElementExpression>
        {
            public CheckboxElementExpression(IScreenElement element)
                : base(element)
            {
            }


            protected override CheckboxElementExpression thisExpression()
            {
                return this;
            }
        }

       
    }
}
